<template>
  <div class="mui-numbox" data-numbox-min="1">
    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
    <input
      id="test"
      class="mui-input-numbox"
      type="number"
      value="1"
      @change="countChanged"
      ref="numbox"
    >
    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.min.js";
export default {
  props: ['maxStock'],
  mounted() {
    mui('.mui-numbox').numbox()
    console.log(this.maxStock);
    mui('.mui-numbox').numbox().setOption('max', this.maxStock)

  },
  methods: {
    countChanged() {
      // 每当文本框的值 改变的时候， 子组件把值传递给父组件
      // console.log(this.$refs.numbox.value)
      this.$emit('getSelectCount', parseInt(this.$refs.numbox.value))
    }
  },
  watch: {
    'maxStock': function (newVal, oldVal) {
      // 通过属性舰艇，动态的给 numbox 设置最大值
      mui('.mui-numbox').numbox().setOption('max', newVal)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>